package com.hqd.ch03.v26.spel.ast;

import com.hqd.ch03.v26.spel.standard.ExpressionState;

/**
 * 二元运算符抽象类
 */
public abstract class Operator extends SpelNodeImpl {
    /**
     * 运算符名称
     */
    private final String operatorName;

    public Operator(String payload, int startPos, int endPos, SpelNodeImpl... operands) {
        super(startPos, endPos, operands);
        this.operatorName = payload;
    }

    @Override
    public Object getValue(ExpressionState state) {
        Object left = getLeftOperand().getValue(state);
        Object right = getRightOperand().getValue(state);
        return getValueInternal(left, right);
    }

    protected abstract Object getValueInternal(Object left, Object right);

    public SpelNodeImpl getLeftOperand() {
        return this.children[0];
    }

    public SpelNodeImpl getRightOperand() {
        return this.children[1];
    }
}
